package com.mpgame.database.mysql.mapper.game;

import com.mpgame.database.mysql.mapper.BaseMapper;
import com.mpgame.database.mysql.model.game.Family;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface FamilyMapper extends BaseMapper<Family> {
    
    @Insert("INSERT INTO family (name, icon_url) VALUES (#{name}, #{iconUrl})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Family family);

    @Select("SELECT * FROM family WHERE id = #{id}")
    Family selectById(@Param("id") int id);

    @Select("SELECT * FROM family WHERE name = #{name}")
    Family selectByName(@Param("name") String name);

    @Select("SELECT * FROM family")
    List<Family> selectAll();

    @Update("UPDATE family SET name = #{name}, icon_url = #{iconUrl} WHERE id = #{id}")
    int updateById(Family family);
}
